package com.bluesky.drcp.business.service;

import com.bluesky.drcp.business.GlobalVariable;
import com.bluesky.drcp.persistence.dao.GlobalVariableDao;

public class GlobalVariableService {
	private GlobalVariableDao globalVariableDao;

	public String getValue(String key) {
		try {

			GlobalVariable o = globalVariableDao.get(key);
			return o.getValue();
		} catch (Exception e) {
			return null;
		}
	}

	public void set(String key, String value) {
		if (value == null) {
			globalVariableDao.delete(key);
		} else {

			GlobalVariable o = globalVariableDao.get(key);
			if (o == null) {
				o = new GlobalVariable();
				o.setId(key);
				o.setValue(value);
			} else {
				o.setValue(value);
			}

			globalVariableDao.saveOrUpdate(o);
		}
	}

	public GlobalVariableDao getGlobalVariableDao() {
		return globalVariableDao;
	}

	public void setGlobalVariableDao(GlobalVariableDao globalVariableDao) {
		this.globalVariableDao = globalVariableDao;
	}
}
